package com.sky.mapper;

import com.github.pagehelper.Page;
import com.sky.anno.AutoFill;
import com.sky.dto.SetmealPageQueryDTO;
import com.sky.entity.Setmeal;
import com.sky.enumeration.OperationType;
import com.sky.vo.DishItemVO;
import com.sky.vo.SetmealVO;
import org.apache.ibatis.annotations.*;

import java.util.HashMap;
import java.util.List;

@Mapper
public interface SetmealMapper {
    @Select("select count(id) from setmeal where category_id = #{categoryId}")
    int countByCategoryId(Long id);

    Page<SetmealVO> selectPage(SetmealPageQueryDTO setmealPageQueryDTO);
        @AutoFill(OperationType.INSERT)
        @Options(useGeneratedKeys = true ,keyProperty = "id")
        @Insert("insert into  setmeal values (null,#{categoryId},#{name},#{price},#{status},#{description},#{image},#{createTime},#{updateTime},#{createUser},#{updateUser})")
        void insertSetmeal(Setmeal setmeal);

        @Select("SELECT  *from setmeal where id= #{id}")
        SetmealVO select(Long id);

    @AutoFill(OperationType.UPDATE)
    void upate(Setmeal setmeal);

    String sql = "UPDATE 表名 SET 字段名=新值 WHERE 条件;";
@Update("UPDATE setmeal set status=#{status} where id=#{id}")
    void upate1(Setmeal setmeal);
@Delete("delete from setmeal where  id=#{id}")
    void deleteById(Long setmealId);
@Select("select *from setmeal where id=#{id}")
    Setmeal selectById(Long id);


    List<Setmeal> selectByCtaegoryId(Setmeal setmeal);

    @Select("select sd.name, sd.copies, d.image, d.description " +
            "from setmeal_dish sd left join dish d on sd.dish_id = d.id " +
            "where sd.setmeal_id = #{setmealId}")
    List<DishItemVO> getDishItemBySetmealId(Long id);
    @Select("SELECT  count(*) from  setmeal where status=#{status}")
   Integer  countByMap(HashMap hashMap);
}
